package cn.gpnusz.oliverwiki.job;

import cn.gpnusz.oliverwiki.service.EbookService;
import cn.gpnusz.oliverwiki.service.EbookSnapshotService;
import cn.gpnusz.oliverwiki.util.SnowFlake;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;


/**
 * @author h0ss
 * @description 电子书生成更新快照的定时任务
 * @date 2021/10/28 1:39
 */
@Component
public class EbookSnapshotJob {
    private static final Logger LOG = LoggerFactory.getLogger(EbookSnapshotJob.class);

    @Resource
    private EbookSnapshotService ebookSnapshotService;

    @Resource
    private SnowFlake snowFlake;

    /**
     * 更新电子书快照
     */
    @Scheduled(cron = "0 0 0/1 * * ?")
    public void docSnapshot() {
        // 设置日志流水号
        MDC.put("LOG_ID", String.valueOf(snowFlake.nextId()));
        LOG.info("生成今日电子书快照开始");
        long start = System.currentTimeMillis();
        ebookSnapshotService.generateSnapshot();
        LOG.info("今日电子书快照生成完毕，耗时 {} 毫秒", System.currentTimeMillis() - start);
    }

}
